import Cookies from 'js-cookie'
// import { findDeptById } from '@/api/dept'

const token = 'token'
const Username = 'Username'

export function getToken() {
  return Cookies.get(token)
}

export function setToken(code) {
  return Cookies.set(token, code)
}

export function removeToken() {
  return Cookies.remove(token)
}

// 判断权限  permission < 80 无管理员权限
export function isAdmin(data) {
  // 若用户信息里有permission字段
  if (data.user.permission) {
    return data.user.permission >= 80
  // 若用户信息里无permission字段 查看部门权限
  } else {
    return data.user.dept.permission >= 80
  }
}

export function getUsername() {
  return Cookies.get(Username)
}

export function setUsername(username) {
  return Cookies.set(Username, username)
}

export function removeUsername() {
  return Cookies.remove(Username)
}
